import {
  imageUrl
} from "../utils/imageutil"
Page({

  data: {
    imageUrl,
    id: '',
    info: null,
    markers: [],
    stepList: [],
    start_img: [],
    end_img: [],
    evaluate_img: [],
    is_water: false,
    rand: 0,
  },

  onLoad(options) {
    this.setData({
      id: options.id
    })
    this.user_order_vehicle_detail()
  },

  user_order_vehicle_detail() {
    getApp().globalData.posts('/index.php/api/app/user/sorting/ouyoung_api/user_order_vehicle_detail?id=' + this.data.id).then(res => {
      let data = res.data.data
      this.setData({
        info: res.data.data,
        start_img: data.start_img ? data.start_img.split(',') : [],
        end_img: data.end_img ? data.end_img.split(',') : [],
        evaluate_img: (data.evaluate && data.evaluate.img) ? data.evaluate.img.split(',') : [],
        markers: [{
          latitude: data.lat,
          longitude: data.lng,
          title: data.address,
          iconPath: imageUrl + '/matron/maps.png',
          width: '48rpx',
          height: '48rpx'
        }],
        stepList: [{
            title: '接单匹配中',
            time: data.create_time
          }, {
            title: '幸福服务员已接单',
            time: data.jd_time
          }, {
            title: '服务开始',
            time: data.start_time
          }, {
            title: '服务完成',
            time: data.end_time
          },
          // {
          //   title: '服务完成',
          //   time: data.work_end_time
          // },
          {
            title: '评价完成',
            time: data.evaluate ? data.evaluate.create_time : ''
          }
        ]
      })
    })
  },

  phoneCall(e) {
    let tel = e.currentTarget.dataset.tel;
    getApp().phoneCall(tel)
  },
  vehicle_cancel(e) {
    let id = e.currentTarget.dataset.id
    getApp().globalData.posts('/index.php/api/app/user/sorting/ouyoung_api/vehicle_cancel', {
      id
    }).then(res => {
      getApp().showModal(res.data.msg).then(() => {
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        prevPage.setData({
          back: true
        });
        wx.navigateBack({
          delta: 1
        });
      })
    })
  },


  to_back() {
    this.setData({
      is_water: false
    })
    wx.reLaunch({
      url: '/pages/index/blank'
    })
  },
  to_list() {
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    prevPage.setData({
      back: true
    });
    this.setData({
      is_water: false
    })
    wx.navigateBack({
      delta: 1
    });
  },
  Vehiclepayv2(e) {
    let order_id = e.currentTarget.dataset.id
    getApp().globalData.post({
      data: {
        do: 'Vehiclepayv2',
        a: 'wxapp2',
        order_id
      }
    }).then(res => {
      let data = res.data.data;
      if (res.data.code == 1) {
        wx.requestPayment({
          nonceStr: data.nonceStr,
          package: data.package,
          paySign: data.paySign,
          signType: data.signType,
          timeStamp: data.timeStamp,
          success: () => {
            this.setData({
              is_water: true,
              rand: data.rand,
            })
          },
          fail: () => {
            getApp().showToast('支付失败！')
          }
        })
      } else {
        getApp().showModal(res.data.msg)
      }
    })
  },

  Hytcpayv2(e) {
    let order_id = e.currentTarget.dataset.id
    getApp().globalData.post({
      data: {
        do: 'Hytcpayv2',
        a: 'wxapp2',
        order_id
      }
    }).then(res => {
      let data = res.data.data;
      if (res.data.code == 1) {
        wx.requestPayment({
          nonceStr: data.nonceStr,
          package: data.package,
          paySign: data.paySign,
          signType: data.signType,
          timeStamp: data.timeStamp,
          success: () => {
            this.setData({
              is_water: true,
              rand: data.rand,
            })
          },
          fail: () => {
            getApp().showToast('支付失败！')
          }
        })
      } else {
        getApp().showModal(res.data.msg)
      }
    })
  },

  contact() {
    getApp().contact()
  },

})